pipeline {
    agent {
        label 'auto_test'
    }
    environment {
        JAVA_TOOL_OPTIONS = "-Dfile.encoding=UTF-8"
    }
    parameters {
        string(name: 'suite_id', defaultValue: '', description: '测试套件ID')
        string(name: 'chennels', defaultValue: 'NQ16', description: '请输入你要执行测试的设备型号')
    }
    stages {
        stage('Clone Repository') {
            steps {
                bat "echo %JAVA_TOOL_OPTIONS%"
                bat "git config --global --add safe.directory *"
                git url: '\\\\192.168.253.179/firmware_src/vpAUT/nvr', branch: 'master'
            }
        }
        stage('Install Dependencies') {
            steps {
                bat 'pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple some-package'
            }
        }
        stage('Generate Shell Scripts') {
            steps {
                // 直接使用 suite_id 和 chennels 参数
                bat "python auto_driver/generate_shell_from_excel.py ${params.suite_id} ${params.chennels}"
            }
        }
        stage('Compress Scripts') {
            steps {
                // Windows 系统使用 tar 命令压缩
                bat '''
                cd nvr_auto_script
                tar -cf ../performance_test.tar performance_test
                cd ..
                tar -cf nvr_auto_script.tar nvr_auto_script
                '''
            }
        }
        stage('Archive Scripts') {
            steps {
                archiveArtifacts artifacts: 'nvr_auto_script.tar', fingerprint: true
                archiveArtifacts artifacts: 'performance_test.tar', fingerprint: true
            }
        }
    }
}